﻿using System;
using ParboiledSharp.parboiled.dataobjects;

namespace ParboiledSharp.parboiled.rules
{
    class Action : Rule
    {
        private readonly Func<Context, bool> _function;
        private readonly System.Action<Context> _action;
        
        public Action(Func<Context, bool> function)
        {
            _function = function;
        }

        public Action(System.Action<Context> action)
        {
            _action = action;
        }

        internal override bool Execute(Context context)
        {
            if (_function != null)
            {
                return _function.Invoke(context);
            }
            else {
                _action.Invoke(context);
                return true;
            }
        }
    }
}
